Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JENKINS-42228] - Prevent JavaScript error on the Jenkins system configuration page #4889

Merged
merged 2 commits into from Aug 3, 2020

Conversation

takashiharano
Copy link
Contributor

@takashiharano takashiharano commented Aug 1, 2020

See JENKINS-42228.

This is a workaround for TypeError by handling undefined object on the Jenkins system configuration page.

The error still occurs in Jenkins 2.250.
Manage Jenkins > Configure Ststem

behavior.js:119 TypeError: Cannot read property 'firstChild' of undefined
    at registerValidator (hudson-behavior.js:511)
    at Array.forEach (<anonymous>)
    at behavior.js:116
    at Array.forEach (<anonymous>)
    at behavior.js:111
    at Array.forEach (<anonymous>)
    at Object.applySubtree (behavior.js:93)
    at select.js:280

The permanent solution is probably to fix the HTML structure or something.
I tried to investigate the root cause, but it seems to be a timing problem and a little bit hard to figure out.
Even so, this workaround would not take a change for the worse.

Here is the error details for further investigation.

error_description

Proposed changelog entries

  • Entry 1: Prevent JavaScript error when registering validators in some cases

Proposed upgrade guidelines

N/A

Submitter checklist

  • (If applicable) Jira issue is well described
  • Changelog entries and upgrade guidelines are appropriate for the audience affected by the change (users or developer, depending on the change). Examples
    • Fill-in the Proposed changelog entries section only if there are breaking changes or other changes which may require extra steps from users during the upgrade
  • Appropriate autotests or explanation to why this change has no tests
  • For dependency updates: links to external changelogs and, if possible, full diffs

Desired reviewers

@mention

Maintainer checklist

Before the changes are marked as ready-for-merge:

  • There are at least 2 approvals for the pull request and no outstanding requests for change
  • Conversations in the pull request are over OR it is explicit that a reviewer does not block the change
  • Changelog entries in the PR title and/or Proposed changelog entries are correct
  • Proper changelog labels are set so that the changelog can be generated automatically
  • If the change needs additional upgrade steps from users, upgrade-guide-needed label is set and there is a Proposed upgrade guidelines section in the PR title. (example)
  • If it would make sense to backport the change to LTS, a Jira issue must exist, be a Bug or Improvement, and be labeled as lts-candidate to be considered (see query).

@@ -500,7 +500,11 @@ var tooltip;
//========================================================
// using tag names in CSS selector makes the processing faster
function registerValidator(e) {
e.targetElement = findFollowingTR(e, "validation-error-area").firstChild.nextSibling;
var tr = findFollowingTR(e, "validation-error-area");
if (!tr || !tr.firstChild) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we add a warning?

Suggested change
if (!tr || !tr.firstChild) {
if (!tr || !tr.firstChild) {
console.warn("Couldn't register validator, start element was", e);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I added a warning log.
The output is like this:
warning

Copy link
Member

@timja timja left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change looks good to me I probably wouldn’t call it a violation.

And would reword the changelog too.

Prevent JavaScript error when registering validators in some cases?

@takashiharano
Copy link
Contributor Author

@timja
Thank you for reviewing.
I also updated the changelog.

@takashiharano takashiharano changed the title Prevent potential access violation on the Jenkins system configuration page Prevent JavaScript error on the Jenkins system configuration page Aug 1, 2020
@oleg-nenashev oleg-nenashev changed the title Prevent JavaScript error on the Jenkins system configuration page [JENKINS-42228] - Prevent JavaScript error on the Jenkins system configuration page Aug 2, 2020
@oleg-nenashev oleg-nenashev added the bug For changelog: Minor bug. Will be listed after features label Aug 2, 2020
Copy link
Member

@oleg-nenashev oleg-nenashev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good as a workaround 👍
We may merge it in 24 hours if there is no negative feedback. Please see the merge process documentation for more information about the merge process

@oleg-nenashev oleg-nenashev added the ready-for-merge The PR is ready to go, and it will be merged soon if there is no negative feedback label Aug 2, 2020
Copy link
Member

@jetersen jetersen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for catching the bug 😅

@oleg-nenashev oleg-nenashev merged commit 0ae7f81 into jenkinsci:master Aug 3, 2020
@oleg-nenashev
Copy link
Member

Thanks a lot for you contributions @takashiharano !

@takashiharano takashiharano deleted the JENKINS-42228 branch March 4, 2021 11:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug For changelog: Minor bug. Will be listed after features ready-for-merge The PR is ready to go, and it will be merged soon if there is no negative feedback
Projects
None yet
5 participants